﻿#include "helpfile.h"
#include "ui_helpfile.h"

helpfile::helpfile(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::helpfile)
{
    ui->setupUi(this);
    textwrite();
    this->setAttribute(Qt::WA_QuitOnClose, false);
    QScroller::grabGesture(ui->textEdit,QScroller::LeftMouseButtonGesture);

#ifdef Q_OS_ANDROID
    int fontId = QFontDatabase::addApplicationFont(":/FontStyle/AlibabaPuHuiTi-3-55-Regular.ttf");
    if (fontId != -1) {
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if (!fontFamilies.isEmpty()) {
            QString familyName = fontFamilies.first();
            QFont font(familyName, 18); // 创建一个QFont对象，设置字体名称和默认大小

            // 使用setFont方法设置字体，传入QFont对象
            ui->pushButton->setFont(font);
        }
    }
#endif
}

helpfile::~helpfile()
{
    delete ui;
}

void helpfile::textwrite(){
//    QFile file("./help/help.html");
    QFile file(":/html/help/help.html");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        // 处理文件打开失败的情况
        qWarning() << "Failed to open file for reading";
    }

    QTextStream in(&file);
    in.setCodec("UTF-8");
    QString htmlContent = in.readAll();

    file.close();
    ui->textEdit->setHtml(htmlContent);
}

void helpfile::on_pushButton_clicked()
{
    this->close();
}
